package parser

import (
	"gitee.com/jnshao/go-start/projects/crawler/engine"
	"log"
	"regexp"
)

var cityListRe = regexp.MustCompile(`<a href="(http://www.zhenai.com/zhenghun/[0-9a-z]+)" [^>]*>([^<]+)</a>`)

// 城市列表解析器
func ParseCityList(content []byte) engine.ParserResult {
	result := engine.NilParser(nil)
	matches := cityListRe.FindAllSubmatch(content, -1)
	for _, subMatches := range matches {
		log.Printf("Got city %s", subMatches[2])
		f := engine.NewFuncParser(ParseCity, "ParseCity", "")
		result.Requests = append(result.Requests, engine.Request{
			URL:    string(subMatches[1]),
			Parser: &f,
		})
	}
	return result
}
